/**
 * Created by user on 2015/10/14.
 */

var H5Service = require('../../../services/mis/operate/h5Service');
var messageUtil = require('../../../common/utils/messageUtil');
var toolUtil = require('../../../common/utils/toolUtil');


exports.h5List = function(req, res) {

    H5Service.h5ListService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when H5List...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when h5List...'));
        }else {
            var data = {
                count:results[0]["count"],
                totalPage: results[0]["totalPage"],
                list: results[1]
            };
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });

};

exports.h5Add = function (req, res) {

    H5Service.h5AddService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when addH5 ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};

exports.h5Delete = function (req, res) {

    H5Service.h5DeleteService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when delete H5 ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};

exports.h5Edit = function (req, res) {

    H5Service.h5EditService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when H5Edit ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};
